package org.greedy.leeCode0012;

public class Solution {

    /*
    * 罗马数字包含以下七种字符： I， V， X， L，C，D 和 M。
    * 字符          数值
        I             1
        V             5
        X             10
        L             50
        C             100
        D             500
        M             1000

    * 详见leecode12题
    * */

    public static void main(String[] args) {

        System.out.println(intToRoman(2000));

    }

    public static String intToRoman(int num) {

        int[] nums={1000,900,500,400,100,90,50,40,10,9,5,4,1};
        String[] strs={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};

        StringBuilder stringBuilder=new StringBuilder();

        int index=0;

        while(num>0){
            if (num>=nums[index]){
                stringBuilder.append(strs[index]);
                num-=nums[index];
            } else {
                index++;
            }

        }
        return stringBuilder.toString();

    }

}
